# -*- coding: utf-8 -*-

# Copyright (C) 2009  Mark McCans <mjmccans@gmail.com>
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyKDE4.kio import *
from PyKDE4.kdeui import *
from PyKDE4.kdecore import *

from gmailconfigform import Ui_Form

# NOTE: After using pyuic4, add "from PyKDE4.kdeui import *" and 
#       "from PyKDE4.kio import *" to the result and remove
#       the import statement at the bottom.

class GmailConfig(QWidget, Ui_Form):
    def __init__(self, settings):
        QWidget.__init__(self)
        
        self.setupUi(self)
        
        # Initialize values
        self.txtUsername.setText(settings["username"])
        self.txtPasswd.setText(settings["passwd"])
        self.intPollingInterval.setValue(settings["pollinterval"])
        self.txtCommand.setText(settings["command"])
        self.colColor.setColor(QColor(settings["textcolor"]))
        self.icoIcon.setIcon(settings["icon"])
        
        # Connect signals
        self.connect(self.btnCommandBrowse, SIGNAL("clicked()"), self.commandBrowse)
        
    def commandBrowse(self):
        fn = KFileDialog.getOpenFileName(KUrl(), "application/x-executable")
        if fn <> "":
            self.txtCommand.setText(fn)
    
    def exportSettings(self):
        settings = {}
        
        settings["username"] = str(self.txtUsername.text())
        settings["passwd"] = str(self.txtPasswd.text())
        settings["pollinterval"] = self.intPollingInterval.value()
        settings["command"] = str(self.txtCommand.text())
        settings["icon"] = str(self.icoIcon.icon())
        settings["textcolor"] = self.colColor.color().name()
        
        return settings